package com.example.demo.itcast;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @Descriotion:
 * @Author longlong.liu
 * @Version 1.0
 * @Date 2021/9/30 16:19
 */
public class BaiduDownloader {
    public static List<String> downloadHtml() throws IOException {
        List<String> res = new ArrayList<>();
        URLConnection urlConnection = new URL("http://www.baidu.com").openConnection();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StandardCharsets.UTF_8));) {
            String line;
            while ((line = br.readLine()) != null) {
                res.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }
}
